package com.black.cat.jvm.instructions.stack.swap;

import com.black.cat.jvm.instructions.base.InstructionNoOperands;
import com.black.cat.jvm.rtda.Frame;
import com.black.cat.jvm.rtda.OperandStack;
import com.black.cat.jvm.rtda.Slot;

/**
 * @Author blackcat
 * @create 2021/8/13 15:16
 * @version: 1.0
 * @description:swap指令交换栈顶的两个变量
 */

public class SWAP extends InstructionNoOperands {

    @Override
    public void execute(Frame frame) {
        OperandStack stack = frame.operandStack();
        Slot slot1 = stack.popSlot();
        Slot slot2 = stack.popSlot();
        stack.pushSlot(slot1);
        stack.pushSlot(slot2);
    }
}
